<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/admin/commons/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>后台管理</title>
    <script type="text/javascript">
        $(function(){
            $("#teacher").addClass("active");
            $("#teacher").find("ul li").eq(0).addClass("active");
        })
    </script>
</head>
<body>
    <div class="admin">
         <form id="form" method="post" action="teacher!delete.action">
            <div class="panel admin-panel">
                <div class="panel-head"><strong>教师列表</strong></div>
                <div class="padding border-bottom">
                    <input type="button" id="selectall" class="button button-small checkall"  checkfor="id" value="全选" />
                    <a href="<%=request.getContextPath() %>/admin/teacher/teacher!toDetail.action"><input type="button" class="button button-small border-green" value="添加教师" /></a>
                    <input type="button" onClick="submit()" class="button button-small border-yellow" value="批量删除" />

                </div>

                <table class="table table-hover">
                    <tr><th width="100">选择</th><th width="120">教师</th><th width="200">教龄</th><th width="400">级别</th><th width="200">已授课</th><th width="200">简介</th><th width="200">操作</th></tr>

                   <s:iterator value="pageBean.data">
                    <tr>
                        <td><input type="checkbox" class="choose" name="id" value="<s:property value="id"/>" /></td>
                        <td><s:property value="name"/></td>
                        <td><s:property value="teachAge"/></td>
                        <td><s:property value="level==1?'初级教师':(level==2?'中级教师':'高级教师')"/></td>
                        <td><s:property value="hasTeachNum"/>节</td>
                        <td><s:property value="teacherDesc"/></td>
                        <td><a class="button border-blue button-little" href="teacher!toDetail.action?teacher.id=<s:property value="id"/>" >修改</a>
                            <a class="button border-red button-little" href="teacher!delete.action?teacher.id=<s:property value="id"/>"
                               onclick="{if (confirm('确认删除?')) {return true;}return false;};">删除</a>
                            <span class="button border-blue button-little" style="cursor: pointer;" onclick="showFaTeach('<s:property value="id"/>');">家教设置</span></td>
                    </tr>
                    </s:iterator>
                </table>
            </div>
         </form>
        <div>
            <s:include value="/admin/commons/page.jsp"></s:include>
        </div>
    </div>
    <div id="faTeach" style="position: fixed;top:20%;left: 20%;height: 60%;width: 50%;z-index: 100;background: #fff;
        padding: 10px 20px;border-radius: 5px;display: none">
        <div style="text-align: center;font-weight: bold">家教设置</div>
        <div class="form-group">
            <div class="label"><label >是否家教</label></div>
            <div class="field">
                <select id="faTeachSelect" class="border radius" style="width:100%;height:35px;"  name="" onchange="openFaTeach();">
                    <option value="0">关闭家教</option>
                    <option value="1">打开家教</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="label"><label >价格时薪</label></div>
            <div class="field">
                <input type="text" class="input" size="50" placeholder="请输入教师时薪"
                       data-validate="required:请输入时薪" value=""/>
            </div>
        </div>
        <div class="form-group">
            <div class="label"><label >单次课最小时长</label></div>
            <div class="field">
                <input type="text" class="input" size="50" placeholder="请输入单次课最小时长（n/小时）"
                       data-validate="required:请输入单次课最小时长" value=""/>
            </div>
        </div>
        <div class="form-group">
            <div class="label"><label >单次课最大时长</label></div>
            <div class="field">
                <input type="text" class="input" size="50" placeholder="请输入单次课最大时长（n/小时）"
                       data-validate="required:请输入单次课最大时长" value=""/>
            </div>
        </div>
        <div class="form-group">
            <div class="label"><label >最少购买课次</label></div>
            <div class="field">
                <input type="text" class="input" size="50" placeholder="请输入最少购买课次（n/次）"
                       data-validate="required:请输入最少购买课次" value=""/>
            </div>
        </div>
        <div class="form-group">
            <div class="label"><label >最多购买课次</label></div>
            <div class="field">
                <input type="text" class="input" size="50" placeholder="请输入最多购买课次（n/次）"
                       data-validate="required:请输入最多购买课次" value=""/>
            </div>
        </div>
        <input hidden value=""/>
        <button class="button bg-blue" onclick="faTeachSet();">提交</button>
        <button class="button bg-blue" onclick="back();">返回</button>

    </div>
    <div id="faTeachBack" style="position: fixed;top:0;left: 0;height: 100%;width: 100%;background: #000;opacity: 0.1;z-index: 99;display: none"></div>

    <script type="text/javascript">
        function submit(){
            var choose= document.getElementsByClassName("choose");
            if($('#selectall').is(':checked')) {
                choose[i].checked = true;
            }else{
                choose[i].checked = false;
            }
            document.getElementBy("form").submit();
        }
        //根据打开关闭家教，做出相应的处理
        function openFaTeach(){
            var type = $('#faTeachSelect option:selected').val();
            if(type==0){//关闭
                $('#faTeach').find('input').attr('disabled','disabled');
                $('#faTeach').find('button').eq(0).attr('disabled','disabled');
            }else{//打开
                $('#faTeach').find('input').removeAttr("disabled");
                $('#faTeach').find('button').eq(0).removeAttr("disabled");
            }
        }
        //c初始化
        openFaTeach();
        //返回
        function back(){
            $('#faTeachBack').hide();
            $('#faTeach').hide();
        }
        //打开设置面板
        var teacherId = 0;
        function showFaTeach(teachId){
            teacherId = teachId;//保存教师的id
            $('#faTeachBack').show();
            $('#faTeach').show();
            //查询数值
            $.ajax({
                'url':'familyTeach!findFaTeach.action',
                'type':'post',
                'data':{'familyTeach.teacherId':teacherId},
                'dataType':'json',
                'success':function(data){
                    if(data==null){
                        $('#faTeach').find('input').eq(0).val("0");
                        $('#faTeach').find('input').eq(1).val("0");
                        $('#faTeach').find('input').eq(2).val("0");
                        $('#faTeach').find('input').eq(3).val("0");
                        $('#faTeach').find('input').eq(4).val("0");
                        $('#faTeach').find('input').eq(5).val("0");
                        $('#faTeach').find('select').val(0);
                    }else {
                        $('#faTeach').find('input').eq(0).val(data.price);
                        $('#faTeach').find('input').eq(1).val(data.startHours);
                        $('#faTeach').find('input').eq(2).val(data.endHours);
                        $('#faTeach').find('input').eq(3).val(data.startTimes);
                        $('#faTeach').find('input').eq(4).val(data.endTimes);
                        $('#faTeach').find('input').eq(5).val(data.id);
                        if(data.isOpen==1){
                            $('#faTeach').find('select').val(data.isOpen);
                        }
                    }

                    openFaTeach();
                },
                'error':function(){
                    alertDiv("查询失败！");
                }
            });

        }
        //家教设置
        function faTeachSet(){
            var price = $('#faTeach').find('input').eq(0).val();
            var startHours = $('#faTeach').find('input').eq(1).val();
            var endHours = $('#faTeach').find('input').eq(2).val();
            var startTimes = $('#faTeach').find('input').eq(3).val();
            var endTimes = $('#faTeach').find('input').eq(4).val();

            var ftId= $('#faTeach').find('input').eq(5).val();
            var isOpen = $('#faTeach').find('select').val();
            var ftTeacherId = teacherId;

            //保存数值
            $.ajax({
                'url':'familyTeach!saveFaTeach.action',
                'type':'post',
                'data':{'familyTeach.id':ftId,'familyTeach.teacherId':ftTeacherId,'familyTeach.price':price,'familyTeach.startHours':startHours
                    ,'familyTeach.endHours':endHours,'familyTeach.startTimes':startTimes,'familyTeach.endTimes':endTimes,'familyTeach.isOpen':isOpen},
                'dataType':'json',
                'success':function(data){
                    alertDiv("保存成功！");
                },
                'error':function(){
                    alertDiv("保存失败！");
                }
            });
        }
    </script>
</body>
</html>
